package com.geekcoding.geekoj.entity;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.TableName;
import com.geekcoding.geekoj.nums.CorrectResult;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Date;
import java.util.Objects;

@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@TableName("geekoj_test_answer")
public class TestAnswer extends BaseEntity{
    private String testId;

    private String answerId;

    private String questionId;

    private String answerValue;

    private String correctorId;

    private String correctorReview;

    @EnumValue
    private CorrectResult correctResult;

    private Date correctTime;

    public void judge(String answer) {
        if(Objects.nonNull(answer) && answer.equals(getAnswerValue())){
            correctResult = CorrectResult.YES;
        }else {
            correctResult = CorrectResult.NO;
        }
        correctTime = new Date();
    }
}
